package com.qyhl.module_practice.newhome;


import com.qyhl.module_practice.common.PracticeUrl;
import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.common.CommonUtils;
import com.qyhl.webtv.commonlib.entity.civilized.PracticeHomeMenuListBean;
import com.qyhl.webtv.commonlib.entity.civilized.PracticeIsVolunteerBean;
import com.qyhl.webtv.commonlib.entity.civilized.PracticeNewHomeBean;

import java.util.List;

public class PracticeNewHomeModel implements PracticeNewHomeContract.PracticeNewHomeModel {
    private PracticeNewHomePresenter mPresenter;

    PracticeNewHomeModel(PracticeNewHomePresenter mPresenter) {
        this.mPresenter = mPresenter;
    }

    @Override
    public void getMenu() {
        EasyHttp.get(PracticeUrl.GET_PRACTICE_HOME_MENU)
                .params("siteId", CommonUtils.getInstance().getSite() + "")
                .execute(new SimpleCallBack<PracticeHomeMenuListBean>() {
                    @Override
                    public void onError(ApiException e) {
                        mPresenter.setMenuList(null);
                    }

                    @Override
                    public void onSuccess(PracticeHomeMenuListBean practiceHomeMenuBeans) {
                        mPresenter.setMenuList(practiceHomeMenuBeans);
                    }
                });
    }

    @Override
    public void getData(String instId, String phone) {
        EasyHttp.get(PracticeUrl.GET_PRACTICE_NEW_HOME)
                .params("insId", instId)
                .params("phone", phone)
                .params("siteId", CommonUtils.getInstance().getSite() + "")
                .execute(new SimpleCallBack<PracticeNewHomeBean>() {
                    @Override
                    public void onError(ApiException e) {
                        if (e.getCode() == 202) {
                            mPresenter.setError("暂无任何内容！");
                        } else {
                            mPresenter.setError("获取详情失败，请重新尝试！");
                        }
                    }

                    @Override
                    public void onSuccess(PracticeNewHomeBean practiceNewHomeBean) {
                        mPresenter.setData(practiceNewHomeBean);
                    }
                });

    }

    @Override
    public void getIsVolunteer(String phone) {

        EasyHttp.post(PracticeUrl.GET_IS_VOLUNTEER)
                .params("siteId", CommonUtils.getInstance().getSite() + "")
                .params("phone", phone)
                .execute(new SimpleCallBack<PracticeIsVolunteerBean>() {
                    @Override
                    public void onError(ApiException e) {
                        mPresenter.setIsVolunteer(null);
                    }

                    @Override
                    public void onSuccess(PracticeIsVolunteerBean practiceIsVolunteerBean) {
                        mPresenter.setIsVolunteer(practiceIsVolunteerBean);
                    }
                });
    }
}
